#include "TexturedFullScreenQuadFX.h"

TexturedFullScreenQuadFX::TexturedFullScreenQuadFX(ID3D11Device* device)
	: AbstractFX(device, L"FX/TexturedFullScreenQuad.fxo") 
{
	//Init pointers.
	texture = NULL;

	//Call init functions
	InitInputLayout(device);
	InitShaderVariablePointers();
}

TexturedFullScreenQuadFX::~TexturedFullScreenQuadFX()
{}

void TexturedFullScreenQuadFX::InitInputLayout(ID3D11Device* device)
{
	//Fillout input layout description.
	const D3D11_INPUT_ELEMENT_DESC PosTex[] = 
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXTURE",  0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
	};

	//Create our input layout 	
	CreateInputLayout(device, PosTex, 2);
}

void TexturedFullScreenQuadFX::InitShaderVariablePointers()
{
	texture = effect->GetVariableByName("textureMap")->AsShaderResource();
	textureMSAA = effect->GetVariableByName("TextureMapMSAA")->AsShaderResource();
	uavBuffFloatVar = effect->GetVariableByName("Buff")->AsUnorderedAccessView();
	srvBufferVar = effect->GetVariableByName("BufferRes")->AsShaderResource();

	rtWidthVar = effect->GetVariableByName("rtWidth")->AsScalar();
	rtHeightVar = effect->GetVariableByName("rtHeight")->AsScalar();

	projVar = effect->GetVariableByName("Proj")->AsMatrix();
}

void TexturedFullScreenQuadFX::SetShaderResource(ID3D11ShaderResourceView* tex)
{
	texture->SetResource(tex);
}

void TexturedFullScreenQuadFX::SetShaderResourceMSAA(ID3D11ShaderResourceView* tex)
{
	textureMSAA->SetResource(tex);
}

void TexturedFullScreenQuadFX::SetUAVFloatBuffer(ID3D11UnorderedAccessView* buff)
{
	uavBuffFloatVar->SetUnorderedAccessView(buff);
}

void TexturedFullScreenQuadFX::SetSRVUint2Buffer(ID3D11ShaderResourceView* buff)
{
	srvBufferVar->SetResource(buff);
}

void TexturedFullScreenQuadFX::SetRTDimentions(float width, float height)
{
	rtWidthVar->SetFloat(width);
	rtHeightVar->SetFloat(height);
}

void TexturedFullScreenQuadFX::SetProj(CXMMATRIX& proj)
{
	projVar->SetMatrix(reinterpret_cast<const float*>(&proj));
}
	